//
//  User.m
//  iNeedish
//
//  Created by Felipe Navarro V. on 30-10-09.
//  Copyright 2009 deis. All rights reserved.
//

#import "User.h"


@implementation User

@synthesize _id, name, lastname, nickname, displayname, biography;
@synthesize  pictureurl, lat, lng, whyhelp, Needs;


-(NSMutableArray *) userAsArray {
	NSMutableArray *arrayUser =  [[NSMutableArray alloc] init];
	[arrayUser addObject:_id];
	[arrayUser addObject:name];
	[arrayUser addObject:lastname];
	[arrayUser addObject:nickname];
	[arrayUser addObject:displayname];
	[arrayUser addObject:biography];
	[arrayUser addObject:pictureurl];
	[arrayUser addObject:lat];
	[arrayUser addObject:lng];
	[arrayUser addObject:whyhelp];
	[arrayUser autorelease];
	return arrayUser;
}


-(User *)decodeUser {
	NSArray *userArchived;// = [NSArray array];
//	User* self = [[User alloc] init];
	NSData *dataRepresentingSavedUser = [[NSUserDefaults standardUserDefaults] objectForKey:@"NeedishUserInfo"];
	if (dataRepresentingSavedUser != nil)
	{
        userArchived = [NSKeyedUnarchiver unarchiveObjectWithData:dataRepresentingSavedUser];
		self._id = [userArchived objectAtIndex:0];
		self.name = [userArchived objectAtIndex:1];
		self.lastname = [userArchived objectAtIndex:2];		
		self.nickname = [userArchived objectAtIndex:3];
		self.displayname = [userArchived objectAtIndex:4];
		self.biography = [userArchived objectAtIndex:5];
		self.pictureurl = [userArchived objectAtIndex:6];
		self.lat = [userArchived objectAtIndex:7];
		self.lng = [userArchived objectAtIndex:8];
		self.whyhelp = [userArchived objectAtIndex:9];
	}	
	
	return self;
}


- (void)dealloc
{
	
	[_id release];
	[name release];
	[lastname release];
	[nickname release];
	[displayname release];
	[biography release];
	[pictureurl release];	
	[lat release];
	[lng release];
	[whyhelp release];
	
	[Needs release];
	[super dealloc];
}

@end
